package com.vfa.fishing;


import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.view.View;
import android.view.Window;
import android.widget.ImageButton;
import android.view.View.OnClickListener;

public class PauseMenuDialog extends Dialog implements OnClickListener
{
	
	ImageButton btnContinue;
	ImageButton btnSave;
	ImageButton btnHelp;
	ImageButton btnSetting;
	ImageButton btnScore;
	ImageButton btnQuit;
	Context dlgContext;
	
	public PauseMenuDialog(Context context) {
		super(context);
		dlgContext = context;
		// TODO Auto-generated constructor stub
		requestWindowFeature(Window.FEATURE_NO_TITLE);  
		setContentView(R.layout.pausemenu);		
		btnContinue = (ImageButton)findViewById(R.id.imgBtnContinue);
		btnContinue.setOnClickListener(this);
		btnSave = (ImageButton)findViewById(R.id.imgBtnSave);
		btnSave.setOnClickListener(this);
		btnHelp = (ImageButton)findViewById(R.id.imgBtnHelp);
		btnHelp.setOnClickListener(this);
		btnSetting = (ImageButton)findViewById(R.id.imgBtnSetting);
		btnSetting.setOnClickListener(this);
		btnScore = (ImageButton)findViewById(R.id.imgBtnScore);
		btnScore.setOnClickListener(this);
		btnQuit = (ImageButton)findViewById(R.id.imgBtnQuit);
		btnQuit.setOnClickListener(this);
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v==btnContinue){
			dismiss();
		}
		else if(v==btnSave){
			 SharedPreferences settings = dlgContext.getSharedPreferences(MenuActivity.PREFS_NAME, 0);
             SharedPreferences.Editor editor = settings.edit();
             editor.putBoolean("saveGamemode", true);// save game
             editor.commit();
             dismiss();
		}
		else if(v==btnHelp){
			Dialog help = new HelpDialog(dlgContext);
        	help.show();
		}
		else if(v==btnSetting){}
		else if(v==btnScore){}
		else if(v==btnQuit){
			DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
			    @Override
			    public void onClick(DialogInterface dialog, int which) {
			        switch (which){
			        case DialogInterface.BUTTON_POSITIVE:
			            //Yes button clicked
			        	 int pid = android.os.Process.myPid();
			                android.os.Process.killProcess(pid);
			                System.exit(0);
			            break;

			        case DialogInterface.BUTTON_NEGATIVE:
			            //No button clicked
			        	dismiss();
			            break;
			        }
			    }
			};

			AlertDialog.Builder builder = new AlertDialog.Builder(dlgContext);
			builder.setMessage("Are you sure want to exit?").setPositiveButton("Yes", dialogClickListener)
			    .setNegativeButton("No", dialogClickListener).show();
		}
	}

}
